package com.gardeneaters.game_v0.autoplay;

import java.util.Vector;

import com.gardeneaters.game_v0.playingfield.Hexagon;
import com.gardeneaters.game_v0.rules.Hexagons;

class Enemy extends Hexagons{

	private Vector <Vector <int[]>> enemyHexPos;
	private Vector <Vector <int[]>> noTeamHexPos;// hex which do not belong to any team
	private int team;
		
	protected Enemy(Hexagon[][] _hexagons, int _team){
		super(_hexagons);
		team = _team;
	}
	
	protected void update(Vector<int[]> clusterCenters){
		this.enemyHexPos = new Vector<Vector <int[]>>();
		this.noTeamHexPos = new Vector<Vector <int[]>>();
		int[] ij;
		for(int k=0; k<clusterCenters.size(); k++)
		{
			ij = clusterCenters.elementAt(k);
			getNearestEnemyHexagons(ij[0], ij[1]);
		}
		
		
	}
	
	private Vector<Integer> getTeamNumOfEnemiesLift(){
		
		Vector<Integer> teams = new Vector<Integer>();
		int team;
		boolean found;
		for(int i=0; i<NumOfHexY; i++)
		{
			for(int j =0; j<NumOfHexX; j++)
			{
				team = hexagons[i][j].getTeam();
				found = false;
				for(int k=0; k<teams.size(); k++)
				{
					if(team == teams.elementAt(k))
						found = true;
				}
				if(!found)
					teams.add(team);
			}
		}
		return teams;
	}
	
	private void getNearestEnemyHexagons(int i, int j){
		
		VectorPos enemy = new VectorPos();// i used this interface to avoid duplicates.. below 'passedIt' condition doesnot guarantee that
		VectorPos noTeam = new VectorPos();// i used this interface to avoid duplicates.. below 'passedIt' condition doesnot guarantee that
		Vector <int[]> posVector = new Vector<int[]>();
		int[] tempPos = {i, j};
		posVector.add(tempPos);
		int[] nextPos;
		boolean passedIt = false;
		
		for(int k=0; k<posVector.size(); k++)
		{
			tempPos = posVector.elementAt(k);
			
			for(int l =1; l<7; l++)
			{
				
				nextPos = getHexagonPos(l, tempPos[0], tempPos[1]);
				if(nextPos==null)
					continue;
				passedIt = VectorPos.isInVector(nextPos[0], nextPos[1], posVector);
				if(!passedIt)
				{
					if(hexagons[nextPos[0]][nextPos[1]].getTeam()== team)
						posVector.add(nextPos);
					else if(hexagons[nextPos[0]][nextPos[1]].getTeam()==0 )
						noTeam.addPosition(nextPos);// do nothing// or add to enemy if required// or some other vector
					else
						enemy.addPosition(nextPos);
				}
			}
		}
		enemyHexPos.add(enemy.getVector());
		noTeamHexPos.add(noTeam.getVector());
	}

	protected Vector<Vector<int[]>> getNoTeamHexPos(){
		return noTeamHexPos;
	}
	
	protected Vector<Vector<int[]>> getEnemyHex(){
		return enemyHexPos;
	}

}
